using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Web.Script.Serialization;
namespace Senparc.Weixin.Helpers
{
	public class SerializerHelper
	{
		public static string DecodeUnicode(Match match)
		{
			string result;
			if (!match.Success)
			{
				result = null;
			}
			else
			{
				char c = (char)int.Parse(match.Value.Remove(0, 2), NumberStyles.HexNumber);
				result = new string(c, 1);
			}
			return result;
		}
		public string GetJsonString(object data)
		{
			JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
			string input = javaScriptSerializer.Serialize(data);
			MatchEvaluator evaluator = new MatchEvaluator(SerializerHelper.DecodeUnicode);
			return Regex.Replace(input, "\\\\u[0123456789abcdef]{4}", evaluator);
		}
	}
}
